package thread;

/**
 * 匿名内部类实现线程的方式
 */
public class ThreadDemo3 {
    public static void main(String[] args) {
        //继承Thread类
        Thread t1=new Thread(){
            public void run(){
                for (int i = 0; i < 1000; i++){
                    System.out.println("线程1:" + i);
                }
            }
        };
        t1.start();

        //实现Runnable接口
        Runnable r1=new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 1000; i++){
                    System.out.println("线程2:" + i);
                }
            }
        };
        Thread t2=new Thread(r1);
        t2.start();
        // Lambda表达式 简化实现Runnable接口
        Thread t3=new Thread(()->{
            for (int i = 0; i < 1000; i++){
                System.out.println("线程3:" + i);
            }
        });
        t3.start();

        //继承Thread类
        Thread t4=new Thread(){
            public void run(){
                for (int i = 0; i < 1000; i++){
                    System.out.println("线程4:" + i);
                }
            }
        };
        t4.start();
        //
        Thread t5=new Thread(()->{
            for (int i = 0; i < 1000; i++){
                System.out.println("线程5:" + i);
            }
        });
        t5.start();
        //


    }
}
